package a07_二叉树;

/**
 * <p>
 * a15_左叶子之和复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/4/10
 */
public class a15_左叶子之和复习3 {

    public int sumOfLeftLeaves(TreeNode root) {
        if (root == null) {
            return 0;
        }

        int leftLeafSum = 0;

        if (root.left != null && root.left.left == null && root.left.right == null) {
            leftLeafSum += root.left.val;
        }else {
            leftLeafSum += sumOfLeftLeaves(root.left);
        }

        leftLeafSum += sumOfLeftLeaves(root.right);

        return leftLeafSum;
    }
}
